package com.ks.community.listenter;

import com.alibaba.excel.context.AnalysisContext;
import com.alibaba.excel.event.AnalysisEventListener;
import com.ks.community.entity.Ingredient;
import com.ks.community.entity.excel.IngredientExcel;
import com.ks.community.service.IngredientService;


public class IngredientListenter extends AnalysisEventListener<IngredientExcel> {

    private IngredientService service;

    public IngredientListenter(){

    }

    public IngredientListenter(IngredientService service) {
        this.service = service;
    }


    @Override
    public void invoke(IngredientExcel ingredientExcel, AnalysisContext analysisContext) {
        Ingredient ingredient = new Ingredient();
        ingredient.setIngredientName(ingredientExcel.getIngredientName());
        ingredient.setIngredientType(ingredientExcel.getIngredientType());
        ingredient.setCalorie(ingredientExcel.getCalorie());
        service.save(ingredient);
    }

    @Override
    public void doAfterAllAnalysed(AnalysisContext analysisContext) {

    }
}
